<div class="tree" id="menu_tree">
	<ul class="tree-default"  style="position:relative; left:-10px;">
		<li id="predef_1" class="last open" rel="root">
		<a style="background-image:url(img/base_comp.gif)" class="f" href="?con=<?php echo $_REQUEST['con']; ?>">Clients</a>
		<?php
            if($clients)
            {
                echo '<ul>';
                $j=2;
				$clientnum = 0;
                foreach($clients as $client)
                {
					$clientnum++;
					$li_class = '';
					if(count($clients) == $clientnum)
					{ $li_class .= 'last'; }
					if($_REQUEST['client'] == $client['id'])
					{ $li_class .= ' open'; }
					$style = ' style="background-image:url(img/client.gif)" ';
					echo '<li id="predef_'.$j.'" class="'.$li_class.'" rel="client">';
					echo '<a rev="'.$site['id'].'" '.$style.' href="?con='.$_REQUEST['con'].'&amp;client='.$client['id'].'">';
					echo $client['name'];
					echo '<input type="hidden" name="item_id" value="'.$client['id'].'" style="display:none" />';
					echo '<input type="hidden" name="item_type" value="client" style="display:none" />';
					echo '</a>';
					$j++;
					$sites  = getSitesList($client['id']);
					if($sites)
					{
						$sitenum = 0;

						echo ' <ul> ';
						foreach($sites as $site)
						{
							$sitenum++;
							$li_class = '';
							if(count($sites) == $sitenum)
							{ $li_class .= 'last'; }
							if($_REQUEST['item'] == $site['id'])
							{ $li_class .= ' open'; }
					
							$style = ' style="background-image:url(img/globe.gif)" ';
							$link = '?con='.$_REQUEST['con'].'&amp;client='.$client['id'].'&amp;item='.$site['id'];
							echo '<li id="predef_'.$j.'" class="'.$li_class.'" rel="site">';
							echo '<a name="site" rev="'.$site['id'].'" '.$style.' href="'.$link.'">';
							echo $site['title'];
							echo '<input type="hidden" name="item_id" value="'.$site['id'].'" style="display:none" />';
							echo '<input type="hidden" name="item_type" value="site" style="display:none" />';
							echo '</a>';
							$j++;
							
							$themes	= getSiteThemes($site['id']);
							if($themes)
							{	
								echo ' <ul> ';
									echo '<li id="predef_'.$j.'" rel="themes">';
									echo '<a>Themes</a>';
									$j++;
									$themesnum = 0;
									echo ' <ul> ';
									
									foreach($themes as $theme)
									{
										$themesnum++;
										if(count($themes) == $themesnum)
										{ $li_class .= 'last'; }
										
										$title = $theme['title'];
										if($theme['site_default'] == 1)
										{ $title = $title.' (D)'; }
										
										$style = ' style="background-image:url(img/imgtheme.gif)" ';
										$link = '?con=2&amp;item='.$theme['id'];
										
										echo '<li id="predef_'.$j.'" class="'.$li_class.' leaf" rel="theme">';
										echo '<a '.$style.' href="'.$link.'">';
										echo $site['title'];
										echo '<input type="hidden" name="item_id" value="'.$theme['id'].'" style="display:none" />';
										echo '<input type="hidden" name="item_type" value="theme" style="display:none" />';
										echo '</a>';
										$j++;
									}
									echo '</ul>';
								echo '</ul>';
							}
							
							echo '</li>';
							
						}
						echo '</ul>';
					}
					echo '</li>';
                }
                echo '</ul>';
            }
        ?>
    	</li>
    </ul>
</div>
<input type="text" id="drag_item_id" name="drag_item_id" value="drag_item_id" />
<input type="text" id="drag_item_type" name="drag_item_type" value="drag_item_type" />
<input type="text" id="drop_item_id" name="drop_item_id" value="drop_item_id" />
<input type="text" id="drop_item_type" name="drop_item_type" value="drop_item_type" />
<input type="text" id="drop_action" name="drop_action" value="move" />
<script type="text/javascript">
function load_tree_menu() 
{
	jQuery("#menu_tree").tree(
	{
		ui: 
		{ 
			animation : 500, 
			rtl : false, 
			dots : true, 
			context : false
		},
		rules: 
		{
			draggable : [ "site", "theme" ], 
			dragrules : [ "site inside client" , "theme inside themes" ]
		},
		callback:
		{
			onchange: function(NODE)
			{
			  if(!first_time) first_time = true;
			  else document.location.href = jQuery(NODE).children('a:eq(0)').attr('href');
			},
			onmove : function(NODE)
			{ 
				document.getElementById('drag_item_id').value = jQuery(NODE).children('a').children('input').eq(0).attr('value');
				document.getElementById('drag_item_type').value = jQuery(NODE).children('a').children('input').eq(1).attr('value');
				document.getElementById('drop_item_id').value = jQuery(NODE).parent('ul').parent('li').children('a').children('input').eq(0).attr('value');
				document.getElementById('drop_item_type').value = jQuery(NODE).parent('ul').parent('li').children('a').children('input').eq(1).attr('value');
				document.getElementById('drop_action').value = 'move';
			}
		}
	});
}
</script>